//
//  LLAlertUtilies.m
//  JunKeDai
//
//  Created by admin on 2018/3/1.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "LLAlertUtilies.h"

@implementation LLAlertUtilies

+ (void)showAlertWithTitle:(NSString *)title message:(NSString *)message confirmTitle:(NSString *)confirmTitle confirmBlock:(dispatch_block_t)confirmBlock cancelTitle:(NSString *)cancelTitle viewController:(UIViewController *)viewController
{
    if (confirmTitle.length == 0) {
        confirmTitle = @"确定";
    }
    if (cancelTitle.length == 0) {
        cancelTitle = @"取消";
    }
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:confirmTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (confirmBlock) {
            confirmBlock();
        }
    }];
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [alertController addAction:confirmAction];
    [alertController addAction:cancleAction];
    [viewController presentViewController:alertController animated:YES completion:nil];
}


+ (void)showSystemSetAlertViewWithTitle:(NSString *)title message:(NSString *)message cancelTitle:(NSString *)cancelTitle confirmTitle:(NSString *)confirmTitle
{
    title = title ? : @"提示";
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *setAction = [UIAlertAction actionWithTitle:confirmTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        if ( [[UIApplication sharedApplication] canOpenURL:url] ) {
            if (@available(iOS 10.0, *)) {
                [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
            } else {
                [[UIApplication sharedApplication]openURL:url];

            }
        }
    }];
    
    cancelTitle = cancelTitle ? : @"取消";
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [alertController addAction:setAction];
    [alertController addAction:cancleAction];
    [[LLRouteTool getCurrentNavigationController] presentViewController:alertController animated:YES completion:nil];
}



@end
